<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="设备名称" prop="devicename">
        <el-input
          v-model="queryParams.devicename"
          placeholder="请输入设备名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="设备编号" prop="devicenumber">
        <el-input
          v-model="queryParams.devicenumber"
          placeholder="请输入设备编号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="设备版本号" prop="deviceversion">
        <el-input
          v-model="queryParams.deviceversion"
          placeholder="请输入设备版本号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="分拣中心ID" prop="sortingid">
        <el-input
          v-model="queryParams.sortingid"
          placeholder="请输入分拣中心ID"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="运营商ID" prop="operatorsid">
        <el-input
          v-model="queryParams.operatorsid"
          placeholder="请输入运营商ID"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="合伙人ID" prop="partnersid">
        <el-input
          v-model="queryParams.partnersid"
          placeholder="请输入合伙人ID"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="场地ID" prop="venuesid">
        <el-input
          v-model="queryParams.venuesid"
          placeholder="请输入场地ID"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="设备状态 1.正常 2.故障 3.离线" prop="devicestatus">
        <el-select v-model="queryParams.devicestatus" placeholder="请选择设备状态 1.正常 2.故障 3.离线" clearable size="small">
          <el-option label="请选择字典生成" value="" />
        </el-select>
      </el-form-item>
      <el-form-item label="设备二维码" prop="deviceqrcode">
        <el-input
          v-model="queryParams.deviceqrcode"
          placeholder="请输入设备二维码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="预警库存标识" prop="stockflag">
        <el-input
          v-model="queryParams.stockflag"
          placeholder="请输入预警库存标识"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="最大库存容量" prop="stockmaxqty">
        <el-input
          v-model="queryParams.stockmaxqty"
          placeholder="请输入最大库存容量"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="省" prop="province">
        <el-input
          v-model="queryParams.province"
          placeholder="请输入省"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="市" prop="city">
        <el-input
          v-model="queryParams.city"
          placeholder="请输入市"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="区" prop="area">
        <el-input
          v-model="queryParams.area"
          placeholder="请输入区"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="详细地址" prop="address">
        <el-input
          v-model="queryParams.address"
          placeholder="请输入详细地址"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="经度" prop="longitude">
        <el-input
          v-model="queryParams.longitude"
          placeholder="请输入经度"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="纬度" prop="latitude">
        <el-input
          v-model="queryParams.latitude"
          placeholder="请输入纬度"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="满溢度" prop="spillover">
        <el-input
          v-model="queryParams.spillover"
          placeholder="请输入满溢度"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="总公司垃圾分成比例" prop="platformgrcomrate">
        <el-input
          v-model="queryParams.platformgrcomrate"
          placeholder="请输入总公司垃圾分成比例"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="总公司商品分成比例" prop="platformgoodscomrate">
        <el-input
          v-model="queryParams.platformgoodscomrate"
          placeholder="请输入总公司商品分成比例"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="分拣中心垃圾分成比例" prop="sortinggrcomrate">
        <el-input
          v-model="queryParams.sortinggrcomrate"
          placeholder="请输入分拣中心垃圾分成比例"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="分拣中心商品分成比例" prop="sortinggoodscomrate">
        <el-input
          v-model="queryParams.sortinggoodscomrate"
          placeholder="请输入分拣中心商品分成比例"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="运营商垃圾分成比例" prop="operatorsgrcomrate">
        <el-input
          v-model="queryParams.operatorsgrcomrate"
          placeholder="请输入运营商垃圾分成比例"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="合伙人垃圾分成比例" prop="partnersgrcomrate">
        <el-input
          v-model="queryParams.partnersgrcomrate"
          placeholder="请输入合伙人垃圾分成比例"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="合伙人商品分成比例" prop="partnersgoodscomrate">
        <el-input
          v-model="queryParams.partnersgoodscomrate"
          placeholder="请输入合伙人商品分成比例"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="合伙人上级：1.分拣中心 2.运营商" prop="partnersparent">
        <el-input
          v-model="queryParams.partnersparent"
          placeholder="请输入合伙人上级：1.分拣中心 2.运营商"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否删除 1.未删除 2.已删除" prop="isdel">
        <el-input
          v-model="queryParams.isdel"
          placeholder="请输入是否删除 1.未删除 2.已删除"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否禁用 1 禁用 2 未禁用" prop="isflag">
        <el-input
          v-model="queryParams.isflag"
          placeholder="请输入是否禁用 1 禁用 2 未禁用"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否缺货 1.未缺货 2.已缺货" prop="isstock">
        <el-input
          v-model="queryParams.isstock"
          placeholder="请输入是否缺货 1.未缺货 2.已缺货"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="故障时间" prop="faulttime">
        <el-date-picker clearable size="small"
          v-model="queryParams.faulttime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择故障时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="离线时间" prop="offlinetime">
        <el-date-picker clearable size="small"
          v-model="queryParams.offlinetime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择离线时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="缺货时间" prop="stockouttime">
        <el-date-picker clearable size="small"
          v-model="queryParams.stockouttime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择缺货时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="满溢时间" prop="spillovertime">
        <el-date-picker clearable size="small"
          v-model="queryParams.spillovertime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择满溢时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="创建时间" prop="ctime">
        <el-date-picker clearable size="small"
          v-model="queryParams.ctime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择创建时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['equipment:device:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['equipment:device:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['equipment:device:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['equipment:device:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="deviceList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="设备主键" align="center" prop="deviceid" />
      <el-table-column label="设备名称" align="center" prop="devicename" />
      <el-table-column label="设备编号" align="center" prop="devicenumber" />
      <el-table-column label="设备版本号" align="center" prop="deviceversion" />
      <el-table-column label="分拣中心ID" align="center" prop="sortingid" />
      <el-table-column label="运营商ID" align="center" prop="operatorsid" />
      <el-table-column label="合伙人ID" align="center" prop="partnersid" />
      <el-table-column label="场地ID" align="center" prop="venuesid" />
      <el-table-column label="设备状态 1.正常 2.故障 3.离线" align="center" prop="devicestatus" />
      <el-table-column label="设备二维码" align="center" prop="deviceqrcode" />
      <el-table-column label="预警库存标识" align="center" prop="stockflag" />
      <el-table-column label="最大库存容量" align="center" prop="stockmaxqty" />
      <el-table-column label="省" align="center" prop="province" />
      <el-table-column label="市" align="center" prop="city" />
      <el-table-column label="区" align="center" prop="area" />
      <el-table-column label="详细地址" align="center" prop="address" />
      <el-table-column label="经度" align="center" prop="longitude" />
      <el-table-column label="纬度" align="center" prop="latitude" />
      <el-table-column label="满溢度" align="center" prop="spillover" />
      <el-table-column label="总公司垃圾分成比例" align="center" prop="platformgrcomrate" />
      <el-table-column label="总公司商品分成比例" align="center" prop="platformgoodscomrate" />
      <el-table-column label="分拣中心垃圾分成比例" align="center" prop="sortinggrcomrate" />
      <el-table-column label="分拣中心商品分成比例" align="center" prop="sortinggoodscomrate" />
      <el-table-column label="运营商垃圾分成比例" align="center" prop="operatorsgrcomrate" />
      <el-table-column label="合伙人垃圾分成比例" align="center" prop="partnersgrcomrate" />
      <el-table-column label="合伙人商品分成比例" align="center" prop="partnersgoodscomrate" />
      <el-table-column label="合伙人上级：1.分拣中心 2.运营商" align="center" prop="partnersparent" />
      <el-table-column label="是否删除 1.未删除 2.已删除" align="center" prop="isdel" />
      <el-table-column label="是否禁用 1 禁用 2 未禁用" align="center" prop="isflag" />
      <el-table-column label="是否缺货 1.未缺货 2.已缺货" align="center" prop="isstock" />
      <el-table-column label="故障时间" align="center" prop="faulttime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.faulttime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="离线时间" align="center" prop="offlinetime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.offlinetime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="缺货时间" align="center" prop="stockouttime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.stockouttime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="满溢时间" align="center" prop="spillovertime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.spillovertime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="创建时间" align="center" prop="ctime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.ctime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['equipment:device:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['equipment:device:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改设备对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="设备名称" prop="devicename">
          <el-input v-model="form.devicename" placeholder="请输入设备名称" />
        </el-form-item>
        <el-form-item label="设备编号" prop="devicenumber">
          <el-input v-model="form.devicenumber" placeholder="请输入设备编号" />
        </el-form-item>
        <el-form-item label="设备版本号" prop="deviceversion">
          <el-input v-model="form.deviceversion" placeholder="请输入设备版本号" />
        </el-form-item>
        <el-form-item label="分拣中心ID" prop="sortingid">
          <el-input v-model="form.sortingid" placeholder="请输入分拣中心ID" />
        </el-form-item>
        <el-form-item label="运营商ID" prop="operatorsid">
          <el-input v-model="form.operatorsid" placeholder="请输入运营商ID" />
        </el-form-item>
        <el-form-item label="合伙人ID" prop="partnersid">
          <el-input v-model="form.partnersid" placeholder="请输入合伙人ID" />
        </el-form-item>
        <el-form-item label="场地ID" prop="venuesid">
          <el-input v-model="form.venuesid" placeholder="请输入场地ID" />
        </el-form-item>
        <el-form-item label="设备状态 1.正常 2.故障 3.离线">
          <el-radio-group v-model="form.devicestatus">
            <el-radio label="1">请选择字典生成</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="设备二维码" prop="deviceqrcode">
          <el-input v-model="form.deviceqrcode" placeholder="请输入设备二维码" />
        </el-form-item>
        <el-form-item label="预警库存标识" prop="stockflag">
          <el-input v-model="form.stockflag" placeholder="请输入预警库存标识" />
        </el-form-item>
        <el-form-item label="最大库存容量" prop="stockmaxqty">
          <el-input v-model="form.stockmaxqty" placeholder="请输入最大库存容量" />
        </el-form-item>
        <el-form-item label="省" prop="province">
          <el-input v-model="form.province" placeholder="请输入省" />
        </el-form-item>
        <el-form-item label="市" prop="city">
          <el-input v-model="form.city" placeholder="请输入市" />
        </el-form-item>
        <el-form-item label="区" prop="area">
          <el-input v-model="form.area" placeholder="请输入区" />
        </el-form-item>
        <el-form-item label="详细地址" prop="address">
          <el-input v-model="form.address" placeholder="请输入详细地址" />
        </el-form-item>
        <el-form-item label="经度" prop="longitude">
          <el-input v-model="form.longitude" placeholder="请输入经度" />
        </el-form-item>
        <el-form-item label="纬度" prop="latitude">
          <el-input v-model="form.latitude" placeholder="请输入纬度" />
        </el-form-item>
        <el-form-item label="满溢度" prop="spillover">
          <el-input v-model="form.spillover" placeholder="请输入满溢度" />
        </el-form-item>
        <el-form-item label="总公司垃圾分成比例" prop="platformgrcomrate">
          <el-input v-model="form.platformgrcomrate" placeholder="请输入总公司垃圾分成比例" />
        </el-form-item>
        <el-form-item label="总公司商品分成比例" prop="platformgoodscomrate">
          <el-input v-model="form.platformgoodscomrate" placeholder="请输入总公司商品分成比例" />
        </el-form-item>
        <el-form-item label="分拣中心垃圾分成比例" prop="sortinggrcomrate">
          <el-input v-model="form.sortinggrcomrate" placeholder="请输入分拣中心垃圾分成比例" />
        </el-form-item>
        <el-form-item label="分拣中心商品分成比例" prop="sortinggoodscomrate">
          <el-input v-model="form.sortinggoodscomrate" placeholder="请输入分拣中心商品分成比例" />
        </el-form-item>
        <el-form-item label="运营商垃圾分成比例" prop="operatorsgrcomrate">
          <el-input v-model="form.operatorsgrcomrate" placeholder="请输入运营商垃圾分成比例" />
        </el-form-item>
        <el-form-item label="合伙人垃圾分成比例" prop="partnersgrcomrate">
          <el-input v-model="form.partnersgrcomrate" placeholder="请输入合伙人垃圾分成比例" />
        </el-form-item>
        <el-form-item label="合伙人商品分成比例" prop="partnersgoodscomrate">
          <el-input v-model="form.partnersgoodscomrate" placeholder="请输入合伙人商品分成比例" />
        </el-form-item>
        <el-form-item label="合伙人上级：1.分拣中心 2.运营商" prop="partnersparent">
          <el-input v-model="form.partnersparent" placeholder="请输入合伙人上级：1.分拣中心 2.运营商" />
        </el-form-item>
        <el-form-item label="是否删除 1.未删除 2.已删除" prop="isdel">
          <el-input v-model="form.isdel" placeholder="请输入是否删除 1.未删除 2.已删除" />
        </el-form-item>
        <el-form-item label="是否禁用 1 禁用 2 未禁用" prop="isflag">
          <el-input v-model="form.isflag" placeholder="请输入是否禁用 1 禁用 2 未禁用" />
        </el-form-item>
        <el-form-item label="是否缺货 1.未缺货 2.已缺货" prop="isstock">
          <el-input v-model="form.isstock" placeholder="请输入是否缺货 1.未缺货 2.已缺货" />
        </el-form-item>
        <el-form-item label="故障时间" prop="faulttime">
          <el-date-picker clearable size="small"
            v-model="form.faulttime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择故障时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="离线时间" prop="offlinetime">
          <el-date-picker clearable size="small"
            v-model="form.offlinetime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择离线时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="缺货时间" prop="stockouttime">
          <el-date-picker clearable size="small"
            v-model="form.stockouttime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择缺货时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="满溢时间" prop="spillovertime">
          <el-date-picker clearable size="small"
            v-model="form.spillovertime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择满溢时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="创建时间" prop="ctime">
          <el-date-picker clearable size="small"
            v-model="form.ctime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择创建时间">
          </el-date-picker>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listDevice, getDevice, delDevice, addDevice, updateDevice } from "@/api/equipment/device";

export default {
  name: "Device",
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 设备表格数据
      deviceList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        devicename: null,
        devicenumber: null,
        deviceversion: null,
        sortingid: null,
        operatorsid: null,
        partnersid: null,
        venuesid: null,
        devicestatus: null,
        deviceqrcode: null,
        stockflag: null,
        stockmaxqty: null,
        province: null,
        city: null,
        area: null,
        address: null,
        longitude: null,
        latitude: null,
        spillover: null,
        platformgrcomrate: null,
        platformgoodscomrate: null,
        sortinggrcomrate: null,
        sortinggoodscomrate: null,
        operatorsgrcomrate: null,
        partnersgrcomrate: null,
        partnersgoodscomrate: null,
        partnersparent: null,
        isdel: null,
        isflag: null,
        isstock: null,
        faulttime: null,
        offlinetime: null,
        stockouttime: null,
        spillovertime: null,
        ctime: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        devicenumber: [
          { required: true, message: "设备编号不能为空", trigger: "blur" }
        ],
        sortingid: [
          { required: true, message: "分拣中心ID不能为空", trigger: "blur" }
        ],
        devicestatus: [
          { required: true, message: "设备状态 1.正常 2.故障 3.离线不能为空", trigger: "blur" }
        ],
        deviceqrcode: [
          { required: true, message: "设备二维码不能为空", trigger: "blur" }
        ],
        stockflag: [
          { required: true, message: "预警库存标识不能为空", trigger: "blur" }
        ],
        stockmaxqty: [
          { required: true, message: "最大库存容量不能为空", trigger: "blur" }
        ],
        platformgrcomrate: [
          { required: true, message: "总公司垃圾分成比例不能为空", trigger: "blur" }
        ],
        platformgoodscomrate: [
          { required: true, message: "总公司商品分成比例不能为空", trigger: "blur" }
        ],
        sortinggrcomrate: [
          { required: true, message: "分拣中心垃圾分成比例不能为空", trigger: "blur" }
        ],
        sortinggoodscomrate: [
          { required: true, message: "分拣中心商品分成比例不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询设备列表 */
    getList() {
      this.loading = true;
      listDevice(this.queryParams).then(response => {
        this.deviceList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        deviceid: null,
        devicename: null,
        devicenumber: null,
        deviceversion: null,
        sortingid: null,
        operatorsid: null,
        partnersid: null,
        venuesid: null,
        devicestatus: 0,
        deviceqrcode: null,
        stockflag: null,
        stockmaxqty: null,
        province: null,
        city: null,
        area: null,
        address: null,
        longitude: null,
        latitude: null,
        spillover: null,
        platformgrcomrate: null,
        platformgoodscomrate: null,
        sortinggrcomrate: null,
        sortinggoodscomrate: null,
        operatorsgrcomrate: null,
        partnersgrcomrate: null,
        partnersgoodscomrate: null,
        partnersparent: null,
        isdel: null,
        isflag: null,
        isstock: null,
        faulttime: null,
        offlinetime: null,
        stockouttime: null,
        spillovertime: null,
        ctime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.deviceid)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加设备";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const deviceid = row.deviceid || this.ids
      getDevice(deviceid).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改设备";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.deviceid != null) {
            updateDevice(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addDevice(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const deviceids = row.deviceid || this.ids;
      this.$confirm('是否确认删除设备编号为"' + deviceids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delDevice(deviceids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('equipment/device/export', {
        ...this.queryParams
      }, `equipment_device.xlsx`)
    }
  }
};
</script>